package org.qf.service;

import com.alibaba.druid.util.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.qf.mapper.ProviderMapper;
import org.qf.mapper.UserMapper;
import org.qf.pojo.Provider;
import org.qf.pojo.Role;
import org.qf.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.security.jca.Providers;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProviderService {
    @Resource
    public ProviderMapper providerMapper;

    // 对供应商进行模糊查询
    public PageInfo<Provider> showProvider(int pageNum, String name){

        //当前页 页面容量
        PageHelper.startPage(pageNum,3);
        Example example=new Example(Provider.class);
        Example.Criteria criteria=example.createCriteria();

        if(!StringUtils.isEmpty(name)) {
            //通过供应商的用户名进行模糊查询
            criteria.andLike("proname", '%' + name + '%');
        }
        List<Provider> Providers =providerMapper.selectByExample(example);
//
        PageInfo<Provider> pageInfo=new PageInfo<Provider>(Providers);
        return pageInfo;
    }

    public List<Provider> selectAll() {
        List<Provider> providers = providerMapper.selectAll();
        return providers;

    }
    // 添加供应商
    public int addProvider(Provider provider) {
        return  providerMapper.insertSelective(provider);
    }

    // 修改某个供应商的功能
    public int EditProvider(Provider provider) {
        return providerMapper.updateByPrimaryKey(provider);
    }

    // 删除某个供应商
    public int DeleteProvider(Provider provider) {
        return providerMapper.deleteByPrimaryKey(provider.getProid());
    }

    public Provider selectById(String proid) {
        return providerMapper.selectByPrimaryKey(proid);
    }

    public Provider selectByID(String id) {
        return providerMapper.selectByPrimaryKey(id);
    }
}
